package com.sea.base.ext.view

import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.ColorInt
import androidx.annotation.ColorRes
import androidx.annotation.Px
import com.custom.widget.databinding.BaseAdapterSimplePictureBinding
import com.sea.base.adapter.holder.BaseViewHolder
import com.sea.base.adapter.interfaces.IListAdapter
import com.sea.base.adapter.simple.BaseAdapter
import com.sea.base.ext.global.dp
import com.sea.base.widget.shape.ShapeTextView

@Suppress("FunctionName")
inline fun SimplePictureAdapter(
    cornerRadius: Int = 0,
    scaleType: ImageView.ScaleType = ImageView.ScaleType.CENTER_CROP,
    list: List<String>? = null,
    crossinline onClickListener: IListAdapter<String>.(holder: BaseViewHolder<BaseAdapterSimplePictureBinding>) -> Unit = {},
) = BaseAdapter.createListVb<BaseAdapterSimplePictureBinding, String>(list) { holder, vb, bean ->
    vb.ivPicture.loadUrl(bean)
    vb.ivPicture.setOnFastClickListener { this.onClickListener(holder) }
    vb.ivPicture.scaleType = scaleType
    if (cornerRadius > 0) {
        vb.ivPicture.setCornerRadius(cornerRadius)
    }
}

@Suppress("FunctionName")
inline fun SimpleSolidShapeAdapter(
    @Px paddingHorizontalPx: Int,
    @Px paddingVerticalPx: Int,
    @ColorRes solidColorRes: Int,
    textSizeSp: Float,
    @ColorRes textColorRes: Int,
    @Px marginHorizontalPx: Int = 0,
    @Px marginVerticalPx: Int = 0,
    @Px radius: Int = 500.dp,
    list: List<String>? = null,
    crossinline onClickListener: IListAdapter<String>.(holder: BaseViewHolder<*>) -> Unit = {},
) = BaseAdapter.createList(list, onCreateCallback = { parent ->
    BaseViewHolder(ShapeTextView(parent.context).apply {
        textSize = textSizeSp
        setTextColorRes(textColorRes)
        buildShape().apply {
            setSolidColorRes(solidColorRes)
            setCornersRadius(radius)
        }
        paddingHorizontal = paddingHorizontalPx
        paddingVertical = paddingVerticalPx
        if (marginHorizontalPx != 0 || marginVerticalPx != 0) {
            layoutParams = parent.getDefLayoutParams()
            setMarginOtherDefault(marginHorizontalPx, marginVerticalPx, marginHorizontalPx, marginVerticalPx)
        }
    })
}) { holder, bean ->
    val tv = holder.itemView as TextView
    tv.text = bean
    tv.setOnFastClickListener { this.onClickListener(holder) }
}

@Suppress("FunctionName")
inline fun SimpleStrokeShapeAdapter(
    @Px paddingHorizontalPx: Int,
    @Px paddingVerticalPx: Int,
    @ColorRes solidColorRes: Int,
    @Px strokeWidth: Int,
    @ColorInt strokeColorInt: Int,
    textSizeSp: Float,
    @ColorRes textColorRes: Int,
    @Px marginHorizontalPx: Int = 0,
    @Px marginVerticalPx: Int = 0,
    @Px radius: Int = 500.dp,
    list: List<String>? = null,
    crossinline onClickListener: IListAdapter<String>.(holder: BaseViewHolder<*>) -> Unit = {},
) = BaseAdapter.createList(list, onCreateCallback = { parent ->
    BaseViewHolder(ShapeTextView(parent.context).apply {
        textSize = textSizeSp
        setTextColorRes(textColorRes)
        buildShape().apply {
            setSolidColorRes(solidColorRes)
            setCornersRadius(radius)
            setStroke(strokeWidth, strokeColorInt)
        }
        paddingHorizontal = paddingHorizontalPx
        paddingVertical = paddingVerticalPx
        if (marginHorizontalPx != 0 || marginVerticalPx != 0) {
            layoutParams = parent.getDefLayoutParams()
            setMarginOtherDefault(marginHorizontalPx, marginVerticalPx, marginHorizontalPx, marginVerticalPx)
        }
    })
}) { holder, bean ->
    val tv = holder.itemView as TextView
    tv.text = bean
    holder.setOnFastClickListener { this.onClickListener(holder) }
}